<template>
	<view>
		<view class="all">
			<view class="lists">
				<view class="box flex_sp" v-for="(item , index) in list" :key="index" @click="address2(item)">
					<view class="left">
						<view class="top">
							<view class="s1">{{item.ad_name}}</view>
							<view class="s2">{{item.ad_tel}}</view>
							<view class="s3" v-show="item.ad_default==1">默认</view>
						</view>
						<view class="bot">
							{{item.ad_street}} {{item.house_number}}
						</view>
					</view>
					<view class="right" @click="bianji(item.id)">
						编辑
					</view>
				</view>
			</view>
		</view>
		<view class="last">
			<view class="box2" @click="address()">
				添加地址
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				chose:""
			};
		},
		onLoad(option) {
			this.chose = option.chose
		},
		onShow() {
			this.getaddlist()
		},
		methods: {
			address2(item){
				if(this.chose){
					uni.$emit('upaddress',item)
					uni.navigateBack({
						delta:1
					})
				}
			},
			bianji(i){
				uni.navigateTo({
					url: '../address/address?id='+i
				})
			},
			async getaddlist() {
				const res = await this.$api("/api/user/addr", 'post').then(res => {
					// console.log(res);
					if (res.data.code == 1) {
						this.list = res.data.data
					}

				})
			},
			address() {
				uni.navigateTo({
					url: '../address/address'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.all {
		background-color: #f5f5f5;
		min-height: 100vh;
		padding: 15px;

		.lists {
			.box {
				margin: 10px 0;
				background: #FFFFFF;
				border-radius: 10px;
				padding: 15px;

				.left {
					width: 80%;

					.top {
						font-size: 14px;
						font-weight: 400;
						color: #000000;
						display: flex;
						align-items: center;

						.s1,
						.s2 {
							margin-right: 10px;
						}

						.s3 {
							border-radius: 5px;
							border: 1px solid #FB774B;
							text-align: center;
							padding: 0px 5px;
							font-size: 12px;
							font-weight: 400;
							color: #FB774B;
						}
					}

					.bot {
						margin: 10px 0 0 0;
						font-size: 14px;
						font-weight: 400;
						color: #000000;
					}
				}

				.right {
					font-size: 14px;
					font-weight: bold;
					color: #FB774B;
				}
			}
		}
	}

	.last {
		width: 100%;
		position: fixed;
		bottom: 0;
		background: #FFFFFF;
		box-shadow: 0px -2px 4px 1px rgba(0, 0, 0, 0.05);
		padding: 10px 10px 20px 10px;
		box-sizing: border-box;

		.box2 {

			padding: 10px 0;
			background: #FB774B;
			border-radius: 40px;
			text-align: center;
			font-size: 14px;
			font-weight: bold;
			color: #FFFFFF;
		}
	}
</style>